]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
keyboard: Refactor code
authorCarlos Garnacho <carlosg@gnome.org>
Tue, 11 Oct 2022 16:23:19 +0000 (18:23 +0200)
committerMarge Bot <marge-bot@gnome.org>
Tue, 18 Oct 2022 19:31:51 +0000 (19:31 +0000)
Move inline anonymous function to be its own. This method
will become asynchronous in following commits.

Part-of: <https://gitlab.gnome.org/GNOME/gnome-shell/-/merge_requests/2508>

js/ui/keyboard.js

index 895691c34ee3112da3d5d9f9649550b8f34dadf4..28369316e13bbe9ca6ddd78b5331984a4a7b3915 100644 (file)
@@ -1510,31 +1510,8 @@ var Keyboard = GObject.registerClass({
                 button.setWidth(key.width);
 
             if (key.action !== 'modifier') {
-                button.connect('commit', (actor, keyval, str) => {
-                    if (this._modifiers.size === 0 && str !== '' &&
-                        keyval && this._oskCompletionEnabled) {
-                        Main.inputMethod.handleVirtualKey(keyval);
-                        return;
-                    }
-
-                    if (str === '' || !Main.inputMethod.currentFocus ||
-                        (keyval && this._oskCompletionEnabled) ||
-                        this._modifiers.size > 0 ||
-                        !this._keyboardController.commitString(str, true)) {
-                        if (keyval !== 0) {
-                            this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_PRESS);
-                            this._keyboardController.keyvalPress(keyval);
-                            GLib.timeout_add(GLib.PRIORITY_DEFAULT, KEY_RELEASE_TIMEOUT, () => {
-                                this._keyboardController.keyvalRelease(keyval);
-                                this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_RELEASE);
-                                this._disableAllModifiers();
-                                return GLib.SOURCE_REMOVE;
-                            });
-                        }
-                    }
-
-                    if (!this._latched)
-                        this._setActiveLayer(0);
+                button.connect('commit', (_actor, keyval, str) => {
+                    this._commitAction(keyval, str);
                 });
             }
 
@@ -1592,6 +1569,33 @@ var Keyboard = GObject.registerClass({
         }
     }
 
+    _commitAction(keyval, str) {
+        if (this._modifiers.size === 0 && str !== '' &&
+            keyval && this._oskCompletionEnabled) {
+            Main.inputMethod.handleVirtualKey(keyval);
+            return;
+        }
+
+        if (str === '' || !Main.inputMethod.currentFocus ||
+            (keyval && this._oskCompletionEnabled) ||
+            this._modifiers.size > 0 ||
+            !this._keyboardController.commitString(str, true)) {
+            if (keyval !== 0) {
+                this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_PRESS);
+                this._keyboardController.keyvalPress(keyval);
+                GLib.timeout_add(GLib.PRIORITY_DEFAULT, KEY_RELEASE_TIMEOUT, () => {
+                    this._keyboardController.keyvalRelease(keyval);
+                    this._forwardModifiers(this._modifiers, Clutter.EventType.KEY_RELEASE);
+                    this._disableAllModifiers();
+                    return GLib.SOURCE_REMOVE;
+                });
+            }
+        }
+
+        if (!this._latched)
+            this._setActiveLayer(0);
+    }
+
     _previousWordPosition(text, cursor) {
         /* Skip word prior to cursor */
         let pos = Math.max(0, text.slice(0, cursor).search(/\s+\S+\s*$/));